package es.seam.myebay;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.contexts.Contexts;

import es.seam.myebay.model.User;

@Name("userq")
@AutoCreate
public class UserQuery {

    @In(value = "entityManager")
    private EntityManager em;
    
    public User readUser(int id) {
        User user = (User) em.find(User.class, id);
        return user;
    }
    
    public User getCurrentUser() {
        User currentUser = (User) Contexts.getSessionContext().get("currentUser");
        return readUser(currentUser.getId());
    }
    
}
